package com.mach.platform.repository;

import com.mach.platform.domain.PitcherAutonomy;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

@Repository
public interface PitcherAutonomyRepo extends BaseRepository<PitcherAutonomy>{

    @Query(value = "SELECT *,DATE_FORMAT(`pitcher_autonomy_time`,'%Y-%m-%d') as time FROM `pitcher_autonomy` where `pitcher_autonomy_time` between ?1 and ?2 GROUP BY class_ban,time",
            countQuery = "select count(*) from (SELECT *,DATE_FORMAT(`pitcher_autonomy_time`,'%Y-%m-%d') as time FROM `pitcher_autonomy` where `pitcher_autonomy_time` between ?1 and ?2 GROUP BY class_ban,time) as t",
            nativeQuery = true)
    Page<PitcherAutonomy> getListByTime(LocalDateTime ldtStartTime, LocalDateTime ldtEndTime, Pageable pageable);

    @Query(value = "select * from pitcher_autonomy where DATE_FORMAT(`pitcher_autonomy_time`,'%Y-%m-%d') = ?1 and class_ban = ?2  ORDER BY `pitcher_autonomy_time`,id", nativeQuery = true)
    List<PitcherAutonomy> getProductionStateByTime(String time, String classBan);
}
